/**
 * 
 */
package pt.mleiria.app.web.bean;


import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import pt.mleiria.app.web.utils.Navigator;
import pt.mleiria.bo.dashboard.LoginEJB;
import pt.mleiria.vo.SessionObjects;


/**
 * @author NB13712
 * 
 */
@ManagedBean(name = "loginBean")
@SessionScoped
public class EntryPointBean extends MasterBean{
	

	@EJB
	private LoginEJB loginEjb;

	public LoginEJB getLoginEjb() {
		return loginEjb;
	}

	private static final long serialVersionUID = 1L;
	private String username = "";
	private String password = "";

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String login() {
		boolean isIt = loginEjb.isUserAuthenticated(username, password);
		if (isIt) {

			setToSession(SessionObjects.USER, loginEjb.getUser());

			setToSession(username, loginEjb.getUser());

			index = Navigator.Dashboard.getValue();
			getLogger(EntryPointBean.class).debug("login link-->" + Navigator.Dashboard.getCompleteLnk());
			return Navigator.Dashboard.getCompleteLnk();
		} else {
			System.out.println("login link-->index");
			return "index";
		}
	}

	public String clear() {
		username = "";
		password = "";
		return "index";
	}
	
	

}
